package de.rj.urwalking.data;

import com.threed.jpct.SimpleVector;

/**
 * 
 * Enhancement of JPCT's SimpleVector class for better accuracy
 * 
 * @author rjj
 * 
 */

public class DoubleVector extends SimpleVector {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public double x;
	public double y;
	public double z;

	public DoubleVector(double x, double y, double z) {
		super(x, y, z);
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public DoubleVector() {

		this(0, 0, 0);

	}
	
	private void updateSuper(){
		super.set((float) x, (float) y, (float) z);
	}
	

	public void set(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}

	public void subtract(SimpleVector subtrahend) {

		x -= subtrahend.x;
		y -= subtrahend.y;
		z -= subtrahend.z;
		
		updateSuper();
	}

	public void matrixMult(double[][] matrix) {

		double x = matrix[0][0] * this.x + matrix[0][1] * this.y + matrix[0][2] * this.z;
		double y = matrix[1][0] * this.x + matrix[1][1] * this.y + matrix[1][2] * this.z;
		double z = matrix[2][0] * this.x + matrix[2][1] * this.y + matrix[2][2] * this.z;

		this.x = x;
		this.y = y;
		this.z = z;

	}

	public void scalarMul(double factor) {
		x *= factor;
		y *= factor;
		z *= factor;
	}

	public void add(double dx, double dy, double dz) {

		x += dx;
		y += dy;
		z += dz;

	}

	public SimpleVector toSimpleVector() {
		return new SimpleVector(x, y, z);
	}

}
